package com.qs.education.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationGradeBean;
import com.qs.education.bean.beans.EducationTeacherGradeClassResponse;
import com.qs.education.bean.entity.EducationGrade;
import com.qs.education.bean.entity.EducationTeacherGradeClass;
import com.qs.education.bean.service.BaseService;
import com.qs.education.service.IGradeAPIService;
import org.springframework.beans.BeanUtils;

/**
 * @class GradeAPIServiceImpl
 * @author Leon
 * @description
 * @date Nov 7, 2018
 */

@Service
public class GradeAPIServiceImpl extends BaseService implements IGradeAPIService {

	@Override
	public ResponseListBean<EducationGradeBean> getAllGrade() {
		List<EducationGrade> list = iEducationGradeDao.getAll(EducationGrade.class);
		ResponseListBean<EducationGradeBean> listBean = new ResponseListBean<EducationGradeBean>();
		for (EducationGrade grade : list) {
			EducationGradeBean bean = new EducationGradeBean();
			BeanUtils.copyProperties(grade,bean);
			listBean.getList().add(bean);
		}
		return listBean;
	}

	@Transactional
	@Override
	public EducationTeacherGradeClassResponse batchSaveGradeAndClass(List<EducationTeacherGradeClass> params) {
		EducationTeacherGradeClassResponse response = new EducationTeacherGradeClassResponse();
		try {
			educationTeacherGradeClass.batchInsert(params);
			response.setStatus("success");
			response.setMessage("保存信息成功");
			return response;
		} catch (Exception e) {
			response.setStatus("error");
			response.setMessage("保存信息失败");
			e.printStackTrace();
			return response;
		}
	}
}
